package com.ly.algorithm.DataStructures.recursion;

/**
 * @Classname MiGong
 * @Description TODO
 * @Date 2020/4/23 9:40
 * @Author 冷心影翼
 */
public class MiGong {

    public static void main(String[] args) {
        int[][] map = new int [10][10];

        for(int i=0;i<10;i++) {
            map[i][9] = 1;
            map[i][0] = 1;
            map[0][i] = 1;
            map[9][i] = 1;
        }

        map[1][2] = 1;
        map[2][2] = 1;
        map[4][6] = 1;
        map[7][6] = 1;
        map[4][5] = 1;
        map[6][7] = 1;
        for (int i = 0;i<10;i++) {
            for (int j = 0; j < 10; j++) {
                System.out.print(map[i][j]+" ");
            }
            System.out.println();
        }

        getWay(1,1,map);
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();
        for (int i = 0;i<10;i++) {
            for (int j = 0; j < 10; j++) {
                System.out.print(map[i][j]+" ");
            }
            System.out.println();
        }
    }

    public static boolean getWay(int i,int j,int[][] map) {
        if(map[8][8] == 2) {
            return true;
        }
        if(map[i][j] == 0) {
            map[i][j] = 2;
            if(getWay(i,j+1,map)) {
                System.out.println(i + " "+ (j+1));
                return true;
            }else if(getWay(i,j-1,map)) {
                System.out.println(i + " "+ (j-1));
                return true;
            }else if(getWay(i-1,j,map)) {
                System.out.println((i-1) + " "+ j);
                return true;
            }else if(getWay(i+1,j,map)) {
                System.out.println((i+1) + " "+ j);
                return true;
            }else {
                map[i][j] = 3;
                return false;
            }
        }else {
            return false;
        }

    }
}
